//
//  UrlCell.m
//  SouthChina
//
//  Created by creator_lq on 14/12/25.
//  Copyright (c) 2014年 科创. All rights reserved.
//

#import "UrlCell.h"

@implementation UrlCell

@synthesize message;
@synthesize publicId;


- (id)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier
{
    self = [super initWithStyle:style reuseIdentifier:reuseIdentifier];
    
    if (self) {
        
        _allcontentView =[[UIImageView alloc]initWithFrame:CGRectZero];
        _backgroundImage =[[UIImageView alloc]initWithFrame:CGRectZero];
        
        
        _titleLabel = [[UILabel alloc]initWithFrame:CGRectZero];
        _authorLabel = [[UILabel alloc]initWithFrame:CGRectZero];

        _timeLabel = [[UILabel alloc]initWithFrame:CGRectZero];

        _lookLabel = [[UILabel alloc]initWithFrame:CGRectZero];

        
        [_lookLabel setFont:[UIFont systemFontOfSize:12]];
        [_titleLabel setFont:[UIFont fontWithName:@"TrebuchetMS-Bold" size:14]];
        [_timeLabel setFont:[UIFont systemFontOfSize:12]];
        [_authorLabel setFont:[UIFont systemFontOfSize:12]];

        _authorLabel.textColor = BASIC_GRAYLINE_COLOR;
        _timeLabel.textColor = BASIC_GRAYLINE_COLOR;

        [self addSubview:_allcontentView];

        [_allcontentView addSubview:_backgroundImage];
        [_backgroundImage addSubview:_titleLabel];
        [_backgroundImage addSubview:_authorLabel];

        [_backgroundImage addSubview:_timeLabel];
        [_backgroundImage addSubview:_lookLabel];

        
        [self setBackgroundColor:[UIColor clearColor]];
        
    }
    return self;
}


- (void)layoutSubviews{
    
    NSDictionary * dataMap =[message getValue:@"url"];
    
    
     CGSize contentSize = [[dataMap objectForKey:@"title"] sizeWithFont:[UIFont systemFontOfSize:14] constrainedToSize:CGSizeMake(SCREEN_WIDTH-4*NEW_CELL_COM_GAP, CGFLOAT_MAX)lineBreakMode:NSLineBreakByWordWrapping];
    
    long totalHeight = contentSize.height +6*NEW_CELL_COM_GAP +TIME_AUTHOR_LOOK_HEIGHT*2;
    
    self.allcontentView.frame =  CGRectMake(0, 0, SCREEN_WIDTH, totalHeight);
    self.backgroundImage.frame =  CGRectMake(NEW_CELL_COM_GAP, NEW_CELL_COM_GAP, SCREEN_WIDTH-2*NEW_CELL_COM_GAP, totalHeight-2*NEW_CELL_COM_GAP);
    [self.backgroundImage setImage:[[UIImage imageNamed:@"news_background_normal"]stretchableImageWithLeftCapWidth:5 topCapHeight:5]];
    
    self.titleLabel.frame = CGRectMake(NEW_CELL_COM_GAP, NEW_CELL_COM_GAP, self.backgroundImage.frame.size.width-2*NEW_CELL_COM_GAP, contentSize.height);
    self.titleLabel.text = [dataMap objectForKey:@"title"];
    self.titleLabel.numberOfLines = 0;//表示label可以多行显示
    self.titleLabel.lineBreakMode = NSLineBreakByWordWrapping;//换行模式，与上面的计算保持一致。
    self.authorLabel.frame = CGRectMake(NEW_CELL_COM_GAP, 2*NEW_CELL_COM_GAP+contentSize.height, self.backgroundImage.frame.size.width/2, TIME_AUTHOR_LOOK_HEIGHT);
    self.authorLabel.text=[dataMap objectForKey:@"author"];

    self.timeLabel.frame = CGRectMake(self.backgroundImage.frame.size.width/2-NEW_CELL_COM_GAP, 2*NEW_CELL_COM_GAP+contentSize.height, self.backgroundImage.frame.size.width/2, TIME_AUTHOR_LOOK_HEIGHT);
    self.timeLabel.textAlignment = NSTextAlignmentRight;
    self.timeLabel.text=[dataMap objectForKey:@"publishTime"];

    self.lookLabel.frame = CGRectMake(NEW_CELL_COM_GAP, 3*NEW_CELL_COM_GAP+contentSize.height+TIME_AUTHOR_LOOK_HEIGHT, self.backgroundImage.frame.size.width, TIME_AUTHOR_LOOK_HEIGHT);
    self.lookLabel.text=@"点击阅读";

    
}

-(void) setMsgCellValue:(Message*)msg publicId:(NSString*)publicIdd{
    
    self.message = msg;
    self.publicId = publicIdd;
    
}





@end
